<template>
	<uni-nav-bar title="配送费膨胀" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	<view class="package_sale datas" style="padding: 10px 0px;margin-bottom:10rpx;">
		<uni-datetime-picker v-model="range" type="daterange" :border="false" :clear-icon="false" rangeSeparator="至"
			@change="change" />
	</view>
	<view class="package_sale space-between">
		<view>单号：</view>
		<input class="uni-input" confirm-type="search" placeholder="请输入订单号" @confirm="confirm" v-model="search"
			@input="interrogate" />
	</view>
	<scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
		:style="{ height: pageHeight + 'px' }">
		<view class="package_sale" @click="navTo('Sale/delivery/deliveryDetail?id='+item.id)" style="margin-top:0px"
			v-for="item in orderLists" :key="item.id">
			<view style="color: #558AF1;text-align: right;">{{item.status_name}}</view>
			<view class="center" style="margin-top:10rpx;">
				<text>单号：{{item.order_sn}}</text>
				<image src="../../../static/saleIcon/icon/copy.svg" mode="" style="width:40rpx;height: 40rpx;"
					@click.stop="copyText(item.order_sn)"></image>
			</view>
			<view class="space-between top">
				<view>{{item.driver_name}}</view>
				<view>{{item.amount}}公斤</view>
			</view>
			<view class="space-between top">
				<view>{{item.createtime}}</view>
				<view>{{item.fill_name}}</view>
			</view>
			<view class="space-between top" v-if="item.status==2">
				<view></view>
				<view class="but"
					@click.stop="navTo('Sale/delivery/addExpansion?id='+item.id+'&name='+item.driver_name)">
					去膨胀</view>
			</view>
		</view>
		<Popu v-if="orderLists.length<1" :pageHeight="pageHeight" text="暂无加注单膨胀"></Popu>
	</scroll-view>
</template>

<script setup lang="ts">
	import { navBack, navTo } from '@/utils/navigator';
	import { ref } from 'vue';
	import { copyText } from '@/utils/copyText';
	import Popu from '@c/earthPushing/common/popu.vue';
	import { getStaffDriverOrder } from '@/gql/earthPushing/teamJoin';
	import { onShow } from '@dcloudio/uni-app';
	import { showLoading, errorToast } from '@/utils/prompt';
	import { toPublish } from '@mqtt';
	import { getDriverID } from '@/stores/driverID';
	import { format, subDays } from 'date-fns';
	const staff_id = getDriverID();
	let now = new Date();
	let end = format(now, 'yyyy-MM-dd');
	let daysAgo = subDays(now, 6);
	let start = format(daysAgo, 'yyyy-MM-dd');
	const range = ref([start, end]);
	const search = ref()
	const inquireAbout = ref(false)
	const pageHeight = ref();
	const orderLists = ref([])
	const lastPage = ref(1);
	const currentPage = ref(1);
	uni.getSystemInfo({
		success: function (res) {
			pageHeight.value = res.windowHeight - 190;
		},
	});
	onShow(() => {
		currentPage.value = 1
		orderLists.value = []
		init()
	})
	function init() {
		showLoading()
		const payload = {
			query: getStaffDriverOrder,
			variables: {
				page: currentPage.value,
				staff_id,
				order_sn: search.value,
				start,
				end,
			},
		};
		toPublish(
			'ql/staff/getStaffDriverOrder',
			payload,
			(obj : any) => {
				const { getStaffDriverOrder } = obj.data;
				orderLists.value = [...orderLists.value, ...getStaffDriverOrder.list];
				lastPage.value = getStaffDriverOrder.lastpage;
			}
		);
	}
	/**
	 * 加载更多
	 */
	function loadMore() {
		if (currentPage.value < lastPage.value) {
			currentPage.value++;
			init();
		}
	}
	/**
	 * 时间筛选
	 * @param sta  开始时间
	 * @param en  结束时间
	 */
	function change([sta, en]) {
		start = sta;
		end = en;
		currentPage.value = 1
		orderLists.value = []
		init()
	}
	/**
	  * 搜索内容
	  * @property {Object} evt 监听搜索框输入信息
	  */
	function interrogate(evt : any) {
		const { detail } = evt;
		if (!detail.value && inquireAbout) {
			currentPage.value = 1;
			orderLists.value = [];
			init()
		}
	}
	/**
	 * 搜索
	 */
	function confirm() {
		if (search.value) {
			inquireAbout.value = search.value ? true : false;
			currentPage.value = 1;
			orderLists.value = [];
			init()
		} else {
			errorToast('请输入您要搜索的内容')
		}
	}
</script>

<style scoped lang="less">
	.uni-input {
		width: 84%;
		border: 1px solid #eee;
		border-radius: 5px;
		padding: 0px 10rpx;
		height: 80rpx;
		box-sizing: border-box;
	}

	.but {
		width: 200rpx;
		height: 78rpx;
		background: #558AF1;
		border-radius: 5px;
		text-align: center;
		line-height: 78rpx;
		color: #fff;
	}

	.top {
		margin-top: 20rpx;
	}
</style>
<style>
	.datas>>>.uni-date__x-input {
		font-size: 32rpx !important;
	}

	.datas>>>.uni-date-x {
		font-size: 32rpx !important;
	}

	.datas>>>.uni-icons {
		font-size: 48rpx !important;
	}

	.datas>>>.uni-date-x {
		padding: 0px 0px 0px 10rpx;
	}

	.datas>>>.select-picker {
		justify-content: flex-end;
		width: 200rpx;
	}

	.datas>>>.select-picker {
		font-size: 26rpx;
	}
</style>